/*
 * ACEDrawingView: https://github.com/acerbetti/ACEDrawingView
 *
 * Copyright (c) 2013 Stefano Acerbetti
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

#import <UIKit/UIKit.h>
//添加静态变量（_selectLev）来区分未选中、选中及编辑状态。
static NSInteger _selectLev;

@class ACEDrawingView;

#define ACEDrawingViewVersion   1.0.0

@protocol ACEHideBottomDelegate <NSObject>

/**
 *  @brief 代理方法
 *
 *  @param toolbarView 本view
 *  @param string      把按钮tag传到代理中
 */
- (void)drawingViewHideBottom:(ACEDrawingView *)view isHidden:(BOOL)isHidden;

@end

@protocol ACEReselectTextDelegate <NSObject>

/**
 *  @brief 代理方法
 *
 *  @param toolbarView 本view
 *  @param string      把按钮tag传到代理中
 */
- (void)drawingViewReselect:(ACEDrawingView *)view;

@end

@protocol ACEDoubleTagsDelegate <NSObject>

/**
 *  @brief 代理方法
 *
 *  @param toolbarView 本view
 *  @param string      把按钮tag传到代理中
 */
- (void)drawingViewDoubleTags:(ACEDrawingView *)view;

@end

@protocol ACESelectedDelegate <NSObject>

/**
 *  @brief 代理方法
 *
 *  @param toolbarView 本view
 *  @param string      把按钮tag传到代理中
 */
- (void)drawingView:(ACEDrawingView *)view isSelected:(BOOL)selected;

@end

@protocol ACEDelegate <NSObject>

/**
 *  @brief 代理方法
 *
 *  @param toolbarView 本view
 *  @param string      把按钮tag传到代理中
 */
- (void)drawingView:(ACEDrawingView *)view isOneTouch:(BOOL)oneTouch;

@end

@protocol ACETouchLocationDelegate <NSObject>

/**
 *  @brief 代理方法
 *
 *  @param toolbarView 本view
 *  @param string      把按钮tag传到代理中
 */
- (void)drawingView:(ACEDrawingView *)view locationX:(float)x locationY:(float)y;

@end


typedef enum {
    ACEDrawingToolTypePen,
    ACEDrawingToolTypeLine,
    ACEDrawingToolTypeRectagleStroke,
    ACEDrawingToolTypeRectagleFill,
    ACEDrawingToolTypeEllipseStroke,
    ACEDrawingToolTypeEllipseFill,
    ACEDrawingToolTypeArrow
} ACEDrawingToolType;

@protocol ACEDrawingViewDelegate, ACEDrawingTool;

@interface ACEDrawingView : UIView <UITextViewDelegate>

@property (nonatomic, strong) NSMutableArray *pathArray;
@property (nonatomic, strong) NSMutableArray *bufferArray;

@property (nonatomic, assign) ACEDrawingToolType drawTool;
@property (nonatomic, assign) id<ACEDrawingViewDelegate> delegate;

// public properties
@property (nonatomic, strong) UIColor *lineColor;
@property (nonatomic, assign) CGFloat lineWidth;
@property (nonatomic, assign) CGFloat lineAlpha;
@property (nonatomic, assign) int movemode;
@property (nonatomic, assign) int hadmove;
@property (nonatomic, assign) int txtmode;
@property (nonatomic, assign) BOOL isstart;
@property (nonatomic, assign) CGPoint startpoint;
@property (nonatomic, assign) BOOL iscancel;
@property (nonatomic, assign) BOOL isdrawing;
@property (nonatomic, assign) BOOL isKeyboardShow;
@property (nonatomic, assign) BOOL isRed;

@property(strong,nonatomic)UIColor *textNormalColor;
@property(strong,nonatomic)UIColor *textSelectColor;
@property (assign,nonatomic) NSInteger tagVar;

@property (nonatomic, assign) NSInteger intBufferArrayMaxCount;

@property(nonatomic,strong)UITextView *currentText;



-(void)addText;
-(void)addTextWithX:(float)pX andY:(float)pY;
-(void)exitText;
-(UIImage *)save;
-(void)tapSelf;


// get the current drawing
@property (nonatomic, strong, readonly) UIImage *image;
@property (nonatomic, readonly) NSUInteger undoSteps;

@property(nonatomic, weak) id<ACEDelegate> aDelegate;
@property(nonatomic, weak) id<ACETouchLocationDelegate> lDelegate;
@property(nonatomic, weak) id<ACESelectedDelegate> sDelegate;
@property(nonatomic, weak) id<ACEDoubleTagsDelegate> tDelegate;
@property(nonatomic, weak) id<ACEReselectTextDelegate> rDelegate;
@property(nonatomic, weak) id<ACEHideBottomDelegate> hDelegate;


@property (nonatomic, assign) BOOL canDraw;
@property (nonatomic, assign) BOOL shouldViewMoveUp;

// erase all
- (void)clear;

// undo / redo
- (BOOL)canUndo;
- (void)undoLatestStep;

- (BOOL)canRedo;
- (void)redoLatestStep;

- (void)deleteTheSelectedDrawingTool;
- (void)changeColor:(UIColor *)color;

@end

#pragma mark -

@protocol ACEDrawingViewDelegate <NSObject>

@optional
- (void)drawingView:(ACEDrawingView *)view willBeginDrawUsingTool:(id<ACEDrawingTool>)tool;
- (void)drawingView:(ACEDrawingView *)view didEndDrawUsingTool:(id<ACEDrawingTool>)tool;



@end
